import { setTimeout } from 'core-js'
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
Vue.use(Vuex)
let actions = {
    jiaOdd(miniStore, value) {
        if (miniStore.state.sum % 2) {

            miniStore.commit('JIA', value)
        }
    },
    jianDyd(miniStore, value) {
        setTimeout(() => {
            miniStore.commit('JIA', value)
        }, 500)
    },
    jianFuwu(miniStore) {
        axios.get('https://api.uixsj.cn/hitokoto/get?type=social').then(
            Response => {
                miniStore.commit('JIA', Response.data.length)
            }
        )
    },
    jiaRen(miniStore, personObj) {
        miniStore.commit('JIA_REN', personObj)
    }
}
let mutations = {
    JIA(state, value) {
        state.sum += value
    },
    JIAN(state, value) {
        state.sum -= value
    },
    JIAN_REN(state, personObj) {
        state.persons.unshift(personObj)
    }
}
let state = {
    sum: 1,
    persons: [
        { id: 'g888g7', name: '张三' },
        { id: 'g148g7', name: '李四' },
        { id: 'g358g7', name: '王五' },
        { id: 'g988g7', name: '芦苇' },

    ]
}
let getters = {

}
export default new Vuex.Store({
    actions,
    mutations,
    state,
    getters
})